package com.wwdx.controller.rest;

import com.google.common.collect.Maps;
import com.wwdx.controller.base.BaseController;
import com.wwdx.model.WwdxXiaodModel;
import com.wwdx.model.dto.ResultBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.Map;

/**
 * @author liguoliang
 * @date 2018/3/1 17:39
 */
@RestController
@RequestMapping("/xiaod")
@Api(tags = "客服消息接口")
public class RestXiaodController extends BaseController{

    /**
     * 查询信息列表
     * @param userid 用户ID
     */
    @RequestMapping("/get")
    @ApiOperation(value = "查询用户消息列表",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userid",value = "用户ID",required = true)
    })
    public ResultBean get(Long userid) {
        Map<String,Object> map = Maps.newHashMapWithExpectedSize(2);
        map.put("total",wwdxXiaodService.selectModelCount(userid));
        map.put("list",wwdxXiaodService.selectModelList(userid));
        return renderSuccess(map);
    }

    /**
     * 保存用户消息
     */
    @RequestMapping(value = "/save")
    @ApiOperation(value = "保存用户消息内容",httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userid",value = "用户ID",required = true),
            @ApiImplicitParam(name = "content",value = "消息内容",required = true)
    })
    public ResultBean save(Long userid, String content){
        WwdxXiaodModel model = WwdxXiaodModel.builder()
                .content(content).userid(userid).type(1).status(0)
                .gmt_created(new Date()).gmt_modified(new Date()).build();
        wwdxXiaodService.save(model);
        return renderSuccess();
    }

    /**
     * 删除用户消息
     * @param id 消息ID
     */
    @RequestMapping(value = "/del")
    @ApiOperation(value = "删除用户消息内容",httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "消息ID",required = true)
    })
    public ResultBean del(Long id) {
        wwdxXiaodService.delete(wwdxXiaodService.getById(id));
        return renderSuccess();
    }
}